package elements;

import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.GradientPaint;
import java.awt.Graphics2D;
import java.awt.Paint;
import java.awt.Stroke;

public class Light implements Drawable{

	int startRindex;
	int startCindex;
	
	int endRindex;
	int endCindex;
	
	int color ;
	public static boolean normal;
	public static float size=10.0f;
	public Light(int startRindex,int startCindex,int endRindex,int endCindex,int color){
		this.startCindex = startCindex;
		this.startRindex = startRindex;
		this.endCindex = endCindex;
		this.endRindex = endRindex;
		this.color = color;
	}
	@Override
	public void draw(Graphics2D g) {
		// TODO Auto-generated method stub
		int[] start = TileMap.tileToPixel(startRindex,startCindex);
		int[] end = TileMap.tileToPixel(endRindex,endCindex);
		
		int startx = start[1];
		int starty = start[0];
		int endx = end[1];
		int endy = end[0];
		Stroke oldStroke = g.getStroke();
		if(normal){
			Color oldColor = g.getColor();
			g.setStroke(new BasicStroke(size));
			g.setColor(new Color(color));
			g.drawLine(startx,starty,endx,endy);
			g.setColor(oldColor);
		}else{
			
			Paint oldPaint = g.getPaint();
			g.setStroke(new BasicStroke(size,BasicStroke.CAP_BUTT,BasicStroke.JOIN_ROUND));			
			float radian = (float)Math.atan2(endy-starty,endx-startx);
			float gx = (float)(size/2* Math.sin(-radian));
			float gy = (float)(size/2* Math.cos(-radian));
			GradientPaint gp = new GradientPaint(startx,starty,new Color(color),startx+gx,starty+gy,Color.black,true);
			g.setPaint(gp);
			g.drawLine(startx,starty,endx,endy);
			g.setPaint(oldPaint);
		}
		g.setStroke(oldStroke);
	}

}
